<%-- 
    Document   : index
    Created on : 21-nov-2013, 12:49:46
    Author     : Javi
--%>

<%@page import="GestorBDatos.UsuarioJpaController"%>
<%@page import="javax.persistence.Persistence"%>
<%@page import="javax.persistence.EntityManagerFactory"%>
<%@page import="java.util.GregorianCalendar"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ page session="true" %>
<%
    HttpSession sesionOk = request.getSession();
    if (sesionOk.getAttribute("Login") != null) {
        sesionOk.invalidate();
        session=request.getSession(true);
        %>
        <jsp:forward page="index.jsp">
        <jsp:param name="error" value=""/>
        </jsp:forward>
        <%
    } 
%>

<!DOCTYPE html>
<html lang="es">
    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Seguridad Informatica</title>
        <link rel="stylesheet" href="css/bootstrap.css">
        <link rel="stylesheet" href="css/signin.css">
    </head>

    <body>
        

        <div class="container">

            <form class="form-signin" role="form" method="post">
                <h2 class="form-signin-heading">Seguridad Informatica</h2>
                <input type="text" name="usuario" class="form-control" placeholder="Login" id="usuario" >
                <input type="password" name="passwd" class="form-control" placeholder="Password" id="passwd" >
                <%
                long espera = 2;
                int maximo_intentos = 5;
                if (request.getParameter("error") != null) {
                    if (request.getParameter("error").equals("1")) {
                        String intentos = request.getParameter("intentos");
                        int intent = Integer.parseInt(intentos);
                        int quedan = maximo_intentos - intent;
                        %>
                        <span class="text-danger">El login o la contraseña son incorrectos, te quedan <%=quedan%> intentos</span>
                        <%
                    } else if (request.getParameter("error").equals("2")) {
                        %>
                        <span class="text-danger">Debes rellenar todos los campos</span>  
                        <%
                    } else if (request.getParameter("error").equals("3")) {
                        %>
                        <span class="text-danger">Sesion caducada</span>
                        <%    
                    } else if (request.getParameter("error").equals("4")) {
                        String hora = request.getParameter("diffMin");
                        long min = Long.parseLong(hora);
                        long faltan = espera - min;
                        %>
                        <span class="text-danger">Debes esperar <%=faltan%> min</span>
                        <%
                    } else if (request.getParameter("error").equals("5")) {
                        %>
                        <span class="text-danger">El login o la contraseña son incorrectos</span>  
                        <%
                    } else if (request.getParameter("error").equals("6")) {
                        %>
                        <span class="text-danger">El usuario todavia no ha sido dado de alta.</span>  
                        <%
                    }
                }%>
                <button class="btn btn-lg btn-primary btn-block" onclick="this.form.action = 'Procesar_Index.jsp'" type="submit">Login</button>
                <button class="btn btn-lg btn-primary btn-block" onclick="this.form.action = 'Pantalla_Alta.jsp'" type="submit">Dar de alta</button>
                <button class="btn btn-lg btn-primary btn-block" onclick="this.form.action = 'Pantalla_Login_Reset_Pass.jsp'" type="submit">¿Has olvidado tu contraseña?</button>
            </form>
        </div>      
                
    </body>
</html>
